import request from '@/utils/request';
import { TableListParams } from './data';

export async function queryRule(params?: Object) {
  return request('/api/auth/group/list', {
    method: 'GET',
    params,
  });
}

export async function removeRule(data: { key: number[] }) {
  return request(`/api/auth/group/${data.key.toString()}`, {
    method: 'DELETE',
    data,
  });
}

export async function addRule(data: object) {
  return request('/api/auth/group', {
    method: 'POST',
    data,
  });
}

export async function updateRule(id: number, data: TableListParams) {
  return request(`/api/auth/group/${id}`, {
    method: 'PUT',
    data,
  });
}

// 获取用户组的功能权限
export function getGroupModules(id: string): Promise<any> {
  return request(`/api/auth/group/${id}/modules`, { method: 'GET' });
}

// 修改用户组的功能权限
export function updateGroupModules(groupId: string, data: object): Promise<any> {
  return request(`/api/auth/group/${groupId}/modules`, {
    method: 'PUT',
    data,
  });
}
